export default {
  namespaced: true,
  state: () => {
    let addressData = uni.getStorageSync('addressData')
    return {
      // 收货地址
      addressData: addressData ? JSON.parse(addressData) : null
    }
  },
  mutations: {
    /**
     * 设置当前的收货地址
     * @param {Object} address
     */
    setAddressData(state, address) {
      state.addressData = address
      this.commit('m_user/save')
    },
    /**
     * 数据持久化
     */
    save(state) {
      // 过滤null
      state.addressData = state.addressData || {}
      uni.setStorageSync('addressData', JSON.stringify(state.addressData))
    }
  }
}
